package com.forcht.client.handle.impl;

import com.forcht.client.Client;
import com.forcht.client.handle.ResponseHandler;
import com.forcht.client.view.FriendsListView;
import com.forcht.common.domain.Response;
import com.forcht.common.domain.User;
import com.forcht.common.util.ProtostuffUtil;
import org.springframework.stereotype.Component;

/**
 * Created by forcht on 2018/4/15.
 */
@Component("hintHandler.login_success")
public class LoginSuccessHintHandler extends ResponseHandler {

    @Override
    public void handle(Response response, Client client) {
        //关闭登录界面
        client.getLoginView().dispose();
        //获取用户的信息
        byte[] body = response.getBody();
        User user = ProtostuffUtil.deserialize(body, User.class);
        user.setSocketChannel(client.getSocketChannel());
        user.setOnline(true);
        client.setUser(user);
        //创建好友列表界面
        FriendsListView friendsListView=new FriendsListView(client);
        client.setFriendsListView(friendsListView);
    }
}
